<script>
    var page_list = "order_list";
    $(function() {
        $("body").layout();
        grid_init($("#grid"),{
            singleSelect: false,
            url:'slave/basis/findList.do',
            columns:[[
                { field: 'o.id', checkbox: true, title: 'ID',width: 80},
                { field: 'o.id' , title: 'ID',width: 80},
                { field: 'o.order_create_time', title: '订单日期',width: 200},
                { field: 'o.tenant_code', title: '总公司代码',width: 100},
                { field: 'o.place_of_loading', title: '开票地点',width: 120},
                { field: 'o.order_number', title: '票号',width: 200},
                { field: 'o.sender', title: '发货人',width: 200},
                { field: 'o.unload_place', title: '目的地',width: 100},
                { field: 'o.goods_name', title: '货名',width: 100},
                { field: 'o.number_of_goods', title: '件数',width: 150},
                { field: 'o.sender_mobile', title: '发货人电话',width: 120},
                { field: 'o.uploadFlag', title: '同步状态',_sql:"case when o.uploadFlag='0' then '失败'" +
                        "  else '成功' end",formatter: function(value,row,index){
                        if (value=="0"){
                            return "失败";
                        } else {
                            return "成功";
                        }
                        return value;
                    }},
                { field: 'o.uploadTime', title: '最后同步日期',width: 120},
                { field: 'o.openid', title: '微信id',width: 120}
                 ]],
            _order:"o.order_create_time desc",
            _db:"slave",
            _append: [],//隐藏列
            _page: page_list,
            _table: "pre_accept_order as o  ",//
            _exportTitle: false,
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });

    });
    setDate('startDate');
    setDate('endDate');
    function setDate(tid){
        var dateTime=new Date();
        var yy=dateTime.getFullYear()+"";
        var mm=dateTime.getMonth()+1+"";
        var dd=dateTime.getDate()+"";
        if(mm.length==1){
            mm="0"+mm;
        }
        if(dd.length==1){
            dd="0"+dd;
        }
        if("startDate"==tid){
            $("#"+tid).val(yy+"-" + mm + "-01" );
        }else{
            $("#"+tid).val(yy+"-" + mm + "-" + dd);
        }

    }
    function uploadData(){
        var grid = grid_get("grid");
        if(grid && grid != null){
            var rows = grid.datagrid("getChecked");
            if(rows == null || rows.length == 0){
                j_tip("请先至少勾选一行数据!","error");
                return;
            }
            var keyIds = "";
            var self = grid[0];
            for(var i=0;i<rows.length;i++){
                var keyId = self.getFieldValue(rows[i],"o.id");
                keyIds += (keyIds==""?"":",")+keyId;
            }
            $.messager.confirm('系统提示', '您确定上传选中的'+rows.length+'条数据?', function(r){
                if (r){
                    self.focus();
                    fy_api.ajax({
                        type:"POST",
                        url: "order/synchronizationOrder.do?_t="+new Date().getTime(),
                        data: {"keyIds":keyIds},
                        success: function(data){
                            console.log("synchronizationOrder:"+data);
                            if(data.object==null || data.object.length==0){
                                if(isSuccess(data)){
                                    j_tip('同步成功','success');
                                    grid.datagrid("reload");
                                }else{
                                    $.messager.alert('系统提示',data.content,'error',function(){
                                        self.focus();
                                    });
                                }
                            }
                        }
                    });
                }else{
                    self.focus();
                }
            });
        }
    }
    function reloadData(){
        setDate('startDate');
        setDate('endDate');
        $("#tenant_code").val("");
        $("#order_number").val("");
        $("#place_of_loading").val("");
        document.getElementById("uploadFlag").value="0";
        grid_get('grid')[0].search();
    }
</script>
<style>
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber
    {
        text-overflow: ellipsis;
    }
</style>
<div id="grid_search" data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}" style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <!--<input type="hidden" name="o.deleteFlag" value="0"/>-->


    <div class="div-item">
        <div class="div-label">开票日期：</div>
        <input name="o.order_create_time" value="" date="start"
               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'endDate\')||\'2030-10-01\'}'});"
               id="startDate" readonly="readonly" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">至：</div>
        <input name="o.order_create_time" value="" date="end"
               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'2030-10-01'});"
               id="endDate" readonly="readonly" clear/>
    </div>

    <div class="div-item">
        <div class="div-label">总公司代码：</div>
        <input name="o.tenant_code"id="tenant_code" type="text" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">票号：</div>
        <input type="text" id="order_number" name="o.order_number" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">开票地点：</div>
        <input type="text" id="place_of_loading" name="o.place_of_loading" clear/>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">下单状态：</div>
        <select name="o.uploadFlag" id="uploadFlag" style="width: 60px;" value="${uploadFlag}" clear>
            <option value="0" >失败</option>
            <option value="1" >成功</option>
        </select>
    </div>


</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton <!--auth-button-->" action="add" data-options="plain:true,iconCls:'icon-config-add'" onclick="uploadData()">重新同步失败数据到TMS</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'" onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'" onclick="reloadData()" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>